package com.alog.yzd.jdbc.hm;

import com.alog.yzd.jdbc.User;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class UserDaoImpl2 {
    private DaoTemplate template = new DaoTemplate();
    public User findUser(String name, String pwd){
        String sql = "select id, name, pwd, birth from user where name = ? and pwd = ?";
        ArrayList<Object> params = new ArrayList<>();
        params.add(name);
        params.add(pwd);
//        User user = (User)template.find(sql, params, new RowMappepr() {
//            @Override
//            public Object map(ResultSet rs) throws SQLException {
//                User user = new User();
//                user.setId(rs.getInt("id"));
//                user.setPwd(rs.getString("pwd"));
//                user.setBirth(rs.getDate("birth"));
//                user.setName(rs.getString("name"));
//                return user;
//            }
//        });
        User user2 = (User)template.find(sql, params, (rs)->{
            User user = new User();
            user.setId(rs.getInt("id"));
            user.setPwd(rs.getString("pwd"));
            user.setBirth(rs.getDate("birth"));
            user.setName(rs.getString("name"));
            return user;
        });
        return user2 ;
    }
}
